package exp;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import stat.DoubleStat;

public class NthColExt {

	private int nOfCol;

	private File file;

	public NthColExt(int c, File file) {
		nOfCol = c;
		this.file = file;
	}

	public double[] ext() {
		List<Double> value = new ArrayList<Double>();
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));

			String in;
			while ((in = br.readLine()) != null) {
				if (in.startsWith("#") || in.length() == 0)
					continue;

				String[] ss = in.split("\\s");
				if (nOfCol > ss.length)
					continue;

				double v = Double.parseDouble(ss[nOfCol - 1]);
				value.add(v);
//				System.out.println("parse: " + v);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		double[] d = new double[value.size()];
		int i = 0;
		for (Iterator<Double> it = value.iterator(); it.hasNext(); ) {
			d[i++] = it.next().doubleValue();
		}
		return d;
	}

	public static void main(String[] args) {
		new DoubleStat(200, new NthColExt(4,new File("rho-zhengwt-1.dat")).ext());
	}
}
